define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function($, undefined, Backend, Table, Form, Template) {

    var Controller = {
        index: function() {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'app_menu/index' + location.search,
                    add_url: 'app_menu/add',
                    edit_url: 'app_menu/edit',
                    del_url: 'app_menu/del',
                    multi_url: 'app_menu/multi',
                    import_url: 'app_menu/import',
                    table: 'app_menu',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                sortName: '',
                escape: false,
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        {
                            field: 'name',
                            title: __('Name'),
                            align: 'left',
                            formatter: function(value, row, index) {
                                return value.toString().replace(/(&|&amp;)nbsp;/g, '&nbsp;');
                            }
                        },
                        { field: 'type', title: __('Type'), searchList: { "1": __('Type 1'), "2": __('Type 2') }, formatter: Table.api.formatter.normal },
                        {
                            field: 'dis',
                            title: __('显示位置'),
                            formatter: function(value, row, index) {
                                if (row.is_display == 1) {
                                    return '<span style="color:success;font-weight:bold;">' + value + '</span>'
                                } else if (row.is_display == 2) {
                                    return '<span style="color:#008800;font-weight:bold;">' + value + '</span>';
                                } else if (row.is_display == 3) {
                                    return '<span style="color:#ff3300;font-weight:bold;">' + value + '</span>';
                                } else {
                                    return '<span style="color:#f39c12;font-weight:bold;">' + value + '</span>';
                                }

                            }
                        },
                        {
                            field: 'dep',
                            title: __('角色组'),
                            formatter: function(value, row, index) {
                                if (row.depart == 0) {
                                    return '<span style="color:success;font-weight:bold;">' + value + '</span>'
                                } else {
                                    return '<span style="color:#f39c12;font-weight:bold;">' + value + '</span>';
                                }

                            }
                        },
                        { field: 'path', title: __('Path'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        { field: 'logo_image', title: __('Logo_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image },
                        { field: 'code', title: __('Code'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        { field: 'sorts', title: __('排序'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        { field: 'status', title: __('Status'), searchList: { "1": __('Status 1'), "2": __('Status 2') }, formatter: Table.api.formatter.status },
                        { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
                    ]
                ],
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function() {
            Controller.api.bindevent();
        },
        edit: function() {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function() {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});